<template>
    <el-card class="shop-card" shadow="hover" :body-style="{ padding: '0px' }">
        <div class="shop-image-container">
            <el-image
                    :src="shop.image"
                    fit="cover"
                    class="shop-image"
            >
                <template #error>
                    <div class="image-error">
                        <el-icon><Picture /></el-icon>
                    </div>
                </template>
            </el-image>
            <div class="shop-rating">
                <el-rate
                        v-model="shop.rating"
                        disabled
                        show-score
                        text-color="#ff9900"
                        score-template="{value}分"
                />
            </div>
        </div>

        <div class="shop-info">
            <h3 class="shop-name">{{ shop.name }}</h3>
            <div class="shop-meta">
        <span class="shop-district">
          <el-icon><Location /></el-icon>
          {{ shop.district }}
        </span>
                <span class="shop-price">
          <el-icon><PriceTag /></el-icon>
          人均¥{{ shop.avgPrice }}
        </span>
            </div>

            <div class="shop-tags">
                <el-tag
                        v-for="tag in shop.tags.slice(0, 3)"
                        :key="tag"
                        size="small"
                        type="info"
                >
                    {{ tag }}
                </el-tag>
                <el-tag v-if="shop.tags.length > 3" size="small" type="info">
                    +{{ shop.tags.length - 3 }}
                </el-tag>
            </div>

            <div class="shop-desc">
                {{ shop.description.substring(0, 50) }}{{ shop.description.length > 50 ? '...' : '' }}
            </div>
        </div>
    </el-card>
</template>

<script setup>
import { Picture, Location, PriceTag } from '@element-plus/icons-vue'

defineProps({
    shop: {
        type: Object,
        required: true
    }
})
</script>

<style scoped>
.shop-card {
    cursor: pointer;
    transition: transform 0.3s;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.shop-card:hover {
    transform: translateY(-5px);
}

.shop-image-container {
    position: relative;
    height: 180px;
    overflow: hidden;
}

.shop-image {
    width: 100%;
    height: 100%;
}

.image-error {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    color: #999;
}

.shop-rating {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 2px 8px;
    border-radius: 4px;
}

.shop-info {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.shop-name {
    margin: 0 0 10px 0;
    font-size: 16px;
    font-weight: bold;
}

.shop-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: #666;
    font-size: 13px;
}

.shop-tags {
    margin-bottom: 10px;
}

.shop-tags .el-tag {
    margin-right: 5px;
    margin-bottom: 5px;
}

.shop-desc {
    color: #666;
    font-size: 13px;
    line-height: 1.5;
    margin-top: auto;
}
</style>